package com.chixing.controller;

import com.chixing.commons.ServerResponse;
import com.chixing.commons.TokenUtil;
import com.chixing.pojo.LoginPerson;
import com.chixing.service.IMycollectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@RestController
//@RequestMapping("/mycollects")
public class MycollectsController {
    @Autowired
    private IMycollectsService mycollectsService;




//    @PostMapping("mycollectAll")
//    private ServerResponse getAllCollectByproId(HttpServletRequest request){
//        String token =request.getHeader("token");
//        Integer personId = TokenUtil.parseToken(token).getPersonId();
//        return mycollectsService.getCollection(personId);
//    }

//    @PostMapping("mycollect/getTotal")
//    public ServerResponse getTotalByPerId(String token){
//        LoginPerson loginPerson = TokenUtil.parseToken(token);
//        Integer personId = loginPerson.getPersonId();
//
//        ServerResponse result = mycollectsService.getTotal(personId);
//        return result;
//    }
//    //查询当前页
//    @PostMapping("getByPagecollect/{pageNum}")
//    public ServerResponse getByPagecollect(@PathVariable("pageNum")Integer pageNum,HttpServletRequest request){
//        System.out.println("当前页码pageNum ："+ pageNum);
//        String token =request.getHeader("token");
//        Integer personId =TokenUtil.parseToken(token).getPersonId();
//        return mycollectsService.getPage(personId,pageNum,token);
//
//    }


    @PostMapping("mycollect/getcollect")
    public ServerResponse getCollect(Integer jobId, String token) {
        ServerResponse result = mycollectsService.getCollection(jobId, token);
        return result;
    }
    @PostMapping("mycollect/delCollect")
    public ServerResponse delCollection(Integer jobId, String token) {
        ServerResponse result = mycollectsService.updateIsDelCollect(jobId, token);
        return result;
    }



    @PostMapping("mycollect/getTotal")
    public ServerResponse getTotalByPerId(String token){
        LoginPerson loginPerson = TokenUtil.parseToken(token);
        Integer personId = loginPerson.getPersonId();

        ServerResponse result = mycollectsService.getTotal(personId);
        return result;
    }
    //查询当前页
    @PostMapping("getByPagecollect/{pageNum}")
    public ServerResponse getByPagecollect(@PathVariable("pageNum")Integer pageNum, HttpServletRequest request){
        System.out.println("当前页码pageNum ："+ pageNum);
        String token =request.getHeader("token");
        Integer personId =TokenUtil.parseToken(token).getPersonId();
        return mycollectsService.getPage(personId,pageNum,token);

    }
}
